(**
 * @copyright (C) 2021 SML# Development Team.
 * @author Atsushi Ohori
 *)
(**
 * user errors detected in type inference phase.
 * @author Liu Bochao
 *)
structure NameEvalError =
struct
local
  (* structure UE = UserError *)

  (*%
     @formatter(Symbol.longsymbol) Symbol.format_longsymbol
   *)
  type longsymbol = Symbol.longsymbol
  (*%
     @formatter(Symbol.symbol) Symbol.format_symbol
   *)
  type symbol = Symbol.symbol
in

  (*%  *)
  type code = string

  (*%
     @formatter(IDCalc.tvar) IDCalc.format_tvar
     @formatter(PatternCalc.plpat) PatternCalc.format_plpat
     @formatter(PatternCalc.ffiTy) PatternCalc.format_ffiTy
     @formatter(RecordLabel.label) RecordLabel.format_label
     @formatter(Absyn.ty) AbsynFormatter.format_ty
     @formatter(Absyn.tvarKind) AbsynFormatter.format_tvarKind
   *)
  exception
  (*%
     @format((code * {tvarList:tvar tvars}))
     "(name evaluation" +d code ")" +d
     "type" +d "variable" +d "kinds" + "form" +d "cycles:" +d tvars(tvar)(",")
   *)
  CyclicKind of (code * {tvarList: IDCalc.tvar list})

  and 
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "unbound" +d "structure name:" +d longsymbol
   *)
  StrNotFound of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Functor" +d "parameter" +d "restriction:" +d longsymbol
   *)
  FunctorParamRestriction of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Primitive" +d "not" +d "found:" +d symbol
   *)
  PrimitiveNotFound of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Runtime" +d "representation" +d "not" +d "found:" +d symbol
   *)
  RuntimeTyNotFound of (code * {symbol: symbol})

  and
  (*%
     @format(code * {symbol})
     "(name evaluation" +d code ")" +d
     "Builtin" +d "type" + "not" +d "found:" +d symbol
   *)
  BuiltinTyNotFound of (code * {symbol: symbol})

  and
  (*%
     @format(code * {symbol})
     "(name evaluation" +d code ")" +d
     "Illegal" +d "runtime" + "type" +d "specification:" +d symbol
   *)
  IllegalBuiltinTy of (code * {symbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "unbound" +d "variable" +d "or" +d "constructor:" +d
     longsymbol
   *)
  VarOrConNotFound of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol})) 
     "(name evaluation" +d code ")" +d
     "unbound" +d "constructor:" +d longsymbol
   *)
  ConNotFound of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "unbound" +d "variable:" +d longsymbol
   *)
  VarNotFound of (code * {longsymbol: longsymbol})

  and
  (*%
    @format((code * {longsymbol}))
    "(name evaluation" +d code ")" +d
    "unbound" +d "type" +d "constructor" +d "or" +d "type" +d
    "alias" ":" +d longsymbol
   *)
  TypNotFound of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "illegal" +d "free" +d "type" +d "variable" +d ":" +d symbol
   *)
  TvarNotFound of (code * {symbol: symbol})

  and
  (*%
     @format((code * {pat}))
     "(name evaluation" +d code ")" +d
     "variable" +d "pattern" +d "expected" +d "for" +d "function" +d "id:"
     +1 pat 
   *)
  IlleagalFunID of (code * {pat : PatternCalc.plpat})

  and
  (*%
    @format((code * {pat}))
     "(name evaluation" +d code ")" +d
    "constructor" +d "expected" +d "in" +d "a"
    +d "constructor" +d "pattern:" +1 pat 
   *)
  NonConstructor of (code * {pat : PatternCalc.plpat})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "where-type" +d "applied" +d "to" +d "inappropriate" +d "type:"
     +d longsymbol 
   *)
  ImproperSigwhere of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "inappropriate" +d "sharing" +d "type:"
     +d longsymbol 
   *)
  ImproperSigshare of (code * {longsymbol : longsymbol})

(* various duplications *)
  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "signature" +d "name:" +d name 
   *)
    DuplicateSigname of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "record" +d "label" +d "in" +d "type" +d "annotation:" +d name
   *)
    DuplicateRecordLabelInRawType of (code * RecordLabel.label)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "record" +d "label" +d "in" +d "expression:" +d name
   *)
    DuplicateRecordLabelInExp of (code * RecordLabel.label)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "record" +d "label" +d "in" +d "record" +d "update:" +d name
   *)
    DuplicateRecordLabelInUpdate of (code * RecordLabel.label)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "record" +d "label" +d "in" +d "pattern:" +d name
   *)
    DuplicateRecordLabelInPat of (code * RecordLabel.label)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "record" +d "label" +d "in" +d "kind" +d "annotation:" +d name
   *)
    DuplicateRecordLabelInKind of (code * RecordLabel.label)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "structure" +d "name:" +d name 
   *)
    DuplicateStrName of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "functor" +d "name:" +d name 
   *)
    DuplicateFunctor of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "type" +d "name:" +d name
   *)
   DuplicateTypName of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "variables" +d "in" +d "patterns:"
     +d name 
   *)
    DuplicateVarInPattern of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "type" +d "parameters"
   *)
    DuplicateTypParms of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "function" +d "names" +d "in" +d 
     "fun" +d "decl:" +d name 
   *)
    DuplicateFunVarInFunDecl of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "rec" +d "var" +d "names" +d 
     "in" +d "rec" +d "decl:" +d name 
   *)
    DuplicateVarInRecDecl of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "typ" +d "in" +d "type" +d "decl:"
      +d name 
   *)
    DuplicateTypInTypeDecl of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "typ" +d "in" +d "datatype" +d "decl:"
      +d name 
   *)
    DuplicateTypInDty of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "Duplicate" +d "type" +d "constructor" +d "in" +d
     "spec:" +d name
   *)
    DuplicateTypInSpec of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "exception" +d "name:" +d name
   *)
   DuplicateExnName of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "variable" +d "or" +d "constructor" +d "name" +d "in"
     +d "spec:" + name
   *)
   DuplicateIdInSpec of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "structure" +d "name" +d "in" +d "spec:" +d name
   *)
   DuplicateStrInSpec of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "constructor" +d "name:" +d  name
   *)
   DuplicateConName of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "variable" +d "name:" +d  name
   *)
   DuplicateVar of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "constructor" +d "name" +d "in" +d "datatype" +d
     "decl:" +d name
   *)
   DuplicateConNameInDty of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "duplicate" +d "structure" +d "name" +d "in" +d "structure" +d
     "binds:" +d name
   *)
   DuplicateStrInStrbind of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "Duplicate" +d "variable" +d "in" +d
     "spec:" +d name
   *)
    DuplicateVarInSpec of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "Duplicate" +d "constructor" +d "in" +d
     "spec:" +d name
   *)
    DuplicateConInSpec of (code * symbol)

  and
  (*%
     @format((code * name))
     "(name evaluation" +d code ")" +d
     "Duplicate" +d "datatype" +d "constructor" +d "in" +d
     "spec:" +d name
   *)
    DuplicateDtyInSpec of (code * symbol)

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "datatype" +d "name" +d "undefined:" +d longsymbol
   *)
    DataTypeNameUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "structure" +d "name" +d "undefined:" +d longsymbol
   *)
    StructureNameUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "replicating" +d "structure" +d "in" +d "functor" +d "argument" +d "not" +d "allowed" +d "in" +d "interface:" 
     +d longsymbol
   *)
    StructureRepOfFuncrorArgInInterface of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "functor" +d "name" +d "undefined:" +d symbol
   *)
    FunctorNameUndefined of (code * {symbol : symbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "exception" +d "undefined:" +d longsymbol
   *)
    ExnUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "exception" +d "expected:" +d longsymbol
   *)
    ExnExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "datatype" +d "name" +d "expected:" +d longsymbol
   *)
    DataTypeNameExpected of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "variable" +d "pattern" +d "expected:" +d  longsymbol
   *)
   VarPatExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "type" +d "constructor" +d
     "arity" +d "does't" +d "agree:" +d longsymbol
   *)
    TypArity of (code * {longsymbol : longsymbol})


  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Constructor" +d "not" +d "specified" +d "in" +d "signature:" +d longsymbol
   *)
    SIGConNotInSig of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Type" +d "constructor" +d
     "arity" +d "does't" +d "agree:" +d longsymbol
   *)
    SIGArity of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Illeagal" +d "where" +d "type" +d "specification:" +d longsymbol
   *)
    SIGIlleagalRealizer of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Illeagal" +d "shareing" +d "specification:" +d longsymbol
   *)
    SIGIlleagalShare of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Type" +d "definition" +d
     "expected:" +d longsymbol
   *)
    SIGTypDefExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Type" +d "constructors" +d
     "do" +d "not" +d "agree:" +d longsymbol
   *)
    SIGTypconMismatch of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "constructor" +d
     "arity" +d "does't" +d "agree:" +d longsymbol
   *)
    SIGDtyArity of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "constructor" +d
     "arity" +d "does't" +d "agree:" +d longsymbol
   *)
    SIGTyconArity of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "expected:" +d longsymbol
   *)
    SIGDtyRequired of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch" +d "(datatype):" +d longsymbol
   *)
    SIGDtyMismatch of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "replication" +d "expected:" +d longsymbol
   *)
    SIGDtyrepRequired of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "replication" +d "mismatch:" +d longsymbol
   *)
    SIGDtyrepId of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "inconsistent" +d "typ" +d "in" + "datatype" +d "replication:" +d longsymbol
   *)
    SIGDtyrepType of (code * {longsymbol : longsymbol})


  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "Type" +d "constructor" +d "undefined:" +d longsymbol
   *)
    SIGTypUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Type" +d "constructor" +d
     "undefined" +d "in" +d "sig" +d "where:" +d longsymbol
   *)
    TypUndefinedInSigwhere of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Type" +d "constructor" +d
     "undefined" +d "in" +d "sharing" +d "constraint:" +d longsymbol
   *)
    TypUndefinedInSigshare of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Type" +d "mismatch" +d
     "in" +d "sig" +d "where:" +d longsymbol
   *)
    TypeErrorInSigwhere of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbolList:longsymbol longsymbols}))
     "(name evaluation" +d code ")" +d
     "Type" +d "constructor" +d
     "arity" +d "mismatch" +d "in" +d "where" +d "type" +d "clause:" 
     +1 longsymbols(longsymbol)(",")
   *)
    ArityErrorInSigwhere of (code * {longsymbolList : longsymbol list})

  and
  (*%
     @format((code * {longsymbolList:longsymbol longsymbols}))
     "(name evaluation" +d code ")" +d
     "Type" +d "constructor" +d
     "arity" +d "mismatch" +d "in" +d "sharing" +d "type" +d "clause:" 
     +1 longsymbols(longsymbol)(",")
   *)
    ArityErrorInSigShare of (code * {longsymbolList : longsymbol list})

  and
  (*%
     @format((code * {longsymbolList:longsymbol longsymbols}))
     "(name evaluation" +d code ")" +d
     "Equality" +d "constraint" +d
     "violation" +d "in" +d "sharing" +d "type" +d "clause:" 
     +1 longsymbols(longsymbol)(",")
   *)
    EqtypeInSigShare of (code * {longsymbolList : longsymbol list})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Equality" +d "constraint" +d
     "violation" +d "in" +d "where" +d "type" +d "clause:" 
     +d longsymbol
   *)
    EqtypeInSigwhere of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbolList:longsymbol longsymbols}))
     "(name evaluation" +d code ")" +d
     "Signature" +d "mismatch" +d
     "in" +d "sharing" +d "type" +d "clause:" +1 longsymbols(longsymbol)(",")
   *)
    SigErrorInSigShare of (code * {longsymbolList : longsymbol list})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "undefined:" +d longsymbol
   *)
    SIGDtyUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "datatype" +d "replication" +d
     "undefined:" +d longsymbol
   *)
    SIGDtyrepUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "constructor" +d "undefined:" +d  
     longsymbol
   *)
    SIGConNotFoundInDty of (code * {longsymbol : longsymbol})
  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "constructor" +d
     "undefined:" +d  
     longsymbol
   *)
    SIGConNotFound of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {typSymbol, conSymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "constructor" +d "of" +d "type" +d typSymbol +d
     "not" +d "exported:" +d
     conSymbol
   *)
    SIGConNotExported of (code * {typSymbol:longsymbol, conSymbol:symbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "constructor" +d
     "undefined:" +d longsymbol
   *)
    SIGConUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "eqtype" +d
     "expected:" +d longsymbol
   *)
    SIGEqtype of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "constructor" +d
     "undefined" +d 
     longsymbol
   *)
    SIGConExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "constructor" +d
     "type" +d 
     "mismatch:" +d 
     longsymbol
   *)
    SIGConType of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "exception" +d
     "undefined" +d 
     longsymbol
   *)
    SIGExnExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch" +d
     "(exception" +d
     "argument):" +d 
     longsymbol
   *)
    SIGExnType of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "variable" +d "undefined:" +d
     longsymbol
   *)
    SIGVarUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbolList:longsymbol longsymbols}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "sharing" +d "constraint" +d
     "not" +d "satisfied:" +1
     longsymbols(longsymbol)(",")
   *)
    SIGShare of (code * {longsymbolList : longsymbol list})


  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Signature mismatch." +d
     "structure" +d "undefined" +d
     longsymbol
   *)
    SIGStrUndefined of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Signature" +d
     "name" +d "undefined" +d
     symbol
   *)
    SigIdUndefined of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "functor" +d
     "name" +d "undefined" +d
     symbol
   *)
    FunIdUndefined of (code * {symbol: symbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "type" +d "name" +d "expected" +d
     "in" +d "where" +d "type" +d "clause:" +d
     longsymbol
   *)
    SpecTyExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "undefined" +d "exception" +d "id:" +d
     longsymbol
   *)
    ExceptionExpected of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "exception" +d "id" +d "expected" +d
     "in" +d "exception" +d "replication:" +d
     longsymbol
   *)
    ExceptionNameUndefined of (code * {longsymbol : longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "type" +d "constructor" +d "undefined" "in" +d
     "spec:" +d longsymbol
   *)
    TypUndefinedInSpec of (code * {longsymbol:longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "structure" +d "undefined" "in" +d
     "spec:" +d longsymbol
   *)
    StrUndefinedInSpec of (code * {longsymbol:longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "datatype" +d "undefined" "in" +d
     "spec:" +d longsymbol
   *)
    DtyUndefinedInSpec of (code * {longsymbol:longsymbol})

(* **********************************************************************)

  and
  (*%
     @format((code * {symbol})) 
     "(name evaluation" +d code ")" +d
     "unbound" +d "exception:" +d symbol
   *)
  ExnNotFound of (code * {symbol: symbol})


  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "unbound" +d "signature:" +d symbol
   *)
  SignatureNotFound of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "unbound" +d "functor:" +d symbol
   *)
  FunctorNotFound of (code * {symbol: symbol})
  
  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Signature" +d "mismatch" +d "(undefined" + d
     "datatype" +d "in" +d "structure):" +d symbol
   *)
  SigMisMatchNotFoundDataTy of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Signature" +d "mismatch" +d "(undefined" +d "data" +d 
     "constructor" +d "in" +d "structure)" symbol
   *)
  SigMisMatchNotFoundCon of (code * {symbol: symbol})

  and

  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Signature" +d "mismatch" +d "(undefined" +d "exception" +d 
     "constructor" +d "in" +d "structure):" +d symbol
   *)
  SigMisMatchNotFoundExn of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Signature" +d "mismatch" +d "(undefined" +d "variable" +d 
     "in" +d "structure):" +d symbol
   *)
  SigMisMatchNotFoundVar of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Signature" +d "mismatch" +d "(undefined" +d "structure" +d 
     "in" +d "structure):" +d symbol
   *)
  SigMisMatchNotFoundStr of (code * {symbol: symbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Interface" +d "mismatch" +d "(undefined" +d "functor" +d 
     "in" +d "implementation):" +d symbol
   *)
  InterfaceMisMatchNotFoundFunctor of (code * {symbol: symbol})

  (* provide error *)
  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Builtin" +d "primitive" +d "in" +d "provide" +d "clause:" +d longsymbol
   *)
  ProvideBuiltIn of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Orverload" +d "primitive" +d "in" +d "provide" +d "clause:" +d longsymbol
   *)
  ProvideOverload of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(missing" + "id):" +d
      + longsymbol
   *)
  ProvideUndefinedID of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {symbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(missing" + "functor" + "definition):" +d
      + symbol
   *)
  ProvideUndefinedFunctor of (code * {symbol: symbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(type" + "mismatch):" +d
     longsymbol
   *)
  ProvideIDType of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(variable" + "id" + "expected):" +d
     longsymbol
   *)
  ProvideVarIDExpected of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(variable" + "alias" + "mismatch):" +d
     longsymbol
   *)
  ProvideVariableAlias of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(missing" + "type" + "name):" +d
     longsymbol
   *)
  ProvideUndefinedTypeName of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(missing" + "exception" + "name):" +d
     longsymbol
   *)
  ProvideUndefinedException of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(type" + "definition):" +d
     longsymbol
   *)
  ProvideInequalTfun of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(datatype" + "expceted):" +d
     longsymbol
   *)
  ProvideDtyExpected of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" +d "check" +d "fails" +d
     "(opaque" +d "type" +d "expceted):" +d
     longsymbol
   *)
  ProvideOpaqueExpected of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(exception" + "type" + "mistch):" +d
     longsymbol
   *)
  ProvideExceptionType of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(generative" +d "exception" +d "definition" +d "expected):" +d
     longsymbol
   *)
  ProvideExceptionDef of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(exception" +d "replication" +d "expected):" +d
     longsymbol
   *)
  ProvideExceptionRep of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(exception" +d "replication" +d "mismatch):" +d
     longsymbol
   *)
  ProvideExceptionRepID of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(type" + "arity" + "mistch):" +d
     longsymbol
   *)
  ProvideArity of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(equality" + "type" + "expected):" +d
     longsymbol
   *)
  ProvideEquality of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(runtime" + "type" + "mismatch):" +d
     longsymbol
   *)
  ProvideRuntimeType of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(constructor" + "type" + "mistch):" +d
     longsymbol
   *)
  ProvideConType of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(constructore" + "undefined):" +d
     longsymbol
   *)
  ProvideUndefinedCon of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(structure" + "undefined):" +d
     longsymbol
   *)
  ProvideUndefinedStr of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(structure" + "replication):" +d
     longsymbol
   *)
  ProvideStrRep of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(functor" + "undefined):" +d
     longsymbol
   *)
  ProvideUndefinedFunctorName of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" + "check" +d "fails" +d
     "(redundant" + "constructor):" +d
     longsymbol
   *)
  ProvideRedundantCon of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" +d "check" +d "fails" +d
     "(functor" +d "parameter" +d "signature" +d "mismatch):" +d
     longsymbol
   *)
  ProvideFunparamMismatch of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" +d "check" +d "fails" +d
     "(functor" +d "body" +d "signature" +d "mismatch):" +d
     longsymbol
   *)
  ProvideFunctorMismatch of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" +d "check" +d "fails" +d
     "(functor" +d "id" +d "mismatch" +d "in" +d "functor" +d "application):" +d
     longsymbol
   *)
  ProvideFunctorIdMismatchInFunapp of (code * {longsymbol: longsymbol})

  and
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "Provide" +d "check" +d "fails" +d
     "(argument" +d "id" +d "mismatch" +d "in" +d "functor" +d "application):" +d
     longsymbol
   *)
  ProvideParamIdMismatchInFunapp of (code * {longsymbol: longsymbol})

  and
  (**
   *)
  (*%
     @format((code * ty))
     "(name evaluation" +d code ")" +d
     "foreign" +d "function" +d "type" +d "is" +d "not" +d "allowed" +d "here:"
     +d ty
   *)
  FFIFunTyIsNotAllowedHere of (code * PatternCalc.ffiTy)

  and
  (**
   *)
  (*%
     @format((code * {longsymbol}))
     "(name evaluation" +d code ")" +d
     "invalid" +d "overload" +d "instance:" +d longsymbol
   *)
  InvalidOverloadInst of (code * {longsymbol: longsymbol})

  and
  (**
   *)
  (*%
     @format(code * s)
     "(name evaluation" +d code ")" +d
     "invalid" +d "kind" +d "name:" +d s
   *)
  InvalidKindName of code * string

  and
  (**
   *)
  (*%
     @format(code * s)
     "(name evaluation" +d code ")" +d
     "invalid" +d "kind:" +d s
   *)
  InvalidKind of code * Absyn.tvarKind

  and
  (**
   *)
  (*%
     @format(code * ty)
     "(name evaluation" +d code ")" +d
     "partial" +d "record" +d "type" +d "not"
     +d "allowed" +d "in" +d "type" +d "declaration:"
     +d ty
   *)
  FlexRecordNotAllowed of code * Absyn.ty

  and
  (**
   *)
  (*%
     @format(code * {symbol})
     "(name evaluation" +d code ")" +d
     "type" +d "constructors" +d "in" +d "the" +d "functor" +d "argument"
     +d "not" +d "allowed" +d "as" +d "opaque" +d "implementations:"
     +d symbol
   *)
  LIFTEDPropNotAllowedInOpaqueInterface of code * {symbol:symbol}

end
end
